#include <REGX52.H>
#include "Timer0.h"
#include "Key.h"
#include "Nixie.h"

sbit Motor = P1^0;

unsigned char counter, threshold;

void main() {
	unsigned char key, mode = 0;
	Timer0_Init();
	
	NixieNoReset(1, mode);

	while (1) {
		key = Key();
		
		if (key == 1) {
			mode++;
			mode %= 4;
			NixieNoReset(1, mode);
			switch (mode) {
				case 0: threshold = 0; break;
				case 1: threshold = 50; break;
				case 2: threshold = 75; break;
				case 3: threshold = 100; break;
			}
		
		}
		
	}
	
}

void Timer0_Isr(void) interrupt 1
{
	TL0 = 0xA4;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
	
	counter++;
	counter %= 100;
	
	if (counter < threshold) {
		Motor = 1;
	} else {
		Motor = 0;
	}
	
}